package com.sunrise.gateway.web.servlet;

import com.dap.utils.TraceIdUtils;
import com.sunrise.gateway.commons.GatewayServletContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public abstract class ServletBase extends HttpServlet {
    protected final static Logger LOGGER = LoggerFactory.getLogger(ServletBase.class);

    @Override
    protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        TraceIdUtils.generateTraceId(true);
        GatewayServletContext.setHttpRequest(req);

        doMyPost(req, resp);
    }
    protected void doMyPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

    @Override
    protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        TraceIdUtils.generateTraceId(true);
        GatewayServletContext.setHttpRequest(req);

        doMyGet(req, resp);
    }
    protected void doMyGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

}
